package com.situ.controller.customer;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.bas_dict.BasDict;
import com.situ.entity.cst_service.CstService;
import com.situ.entity.might.SysMight;
import com.situ.entity.orders.Orders;
import com.situ.entity.user.SysUser;
import com.situ.service.bas_dict.BasDictService;
import com.situ.service.user.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.customer.CstCustomerService;
import com.situ.entity.customer.CstCustomer;
import com.situ.util.*;

import java.util.List;

/**
 * CstCustomer的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class CstCustomerController {

	/** CstCustomerService服务 */
	@Autowired
	private CstCustomerService cstCustomerService;
    @Autowired
    private BasDictService basDictService;

    /**
	 * 查询所有CstCustomer数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/CstCustomer/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(CstCustomer value) {

		return ResponseData.ok().putDataValue("list",cstCustomerService.find(value));
	}
	
	/**
	 * 通过id查询CstCustomer数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstCustomer/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") String id) {
		 return ResponseData.ok().putDataValue("obj",cstCustomerService.findOne(id));
	}
	
	/**
	 * 插入CstCustomer属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstCustomer/save")
	public ResponseData save(CstCustomer value) {
		return ResponseData.ok().putDataValue("obj", cstCustomerService.saveNotNull(value));
	}
	
	/**
	 * 更新CstCustomer属性不为空的数据方法
	 * 
	 * @return
     *
     *
     * @RequestMapping(value = "/CstCustomer/update", produces = {"application/json;charset=UTF-8"})
     * 	public ResponseData update(CstCustomer value) {
     * 		return ResponseData.ok().putDataValue("obj",cstCustomerService.updateNotNullById(value));
     * 	}
	 */


	/**
	 * 通过id删除CstCustomer数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstCustomer/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") String id) {
		return ResponseData.ok().putDataValue("obj",cstCustomerService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/CstCustomer/querBylike", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(CstCustomer value,
                                  @RequestParam(defaultValue = "1",required = false) int pageNum ,
                                  @RequestParam(defaultValue = "4",required = false) int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        //System.out.println("name:"+value.getCust_name());
        List<CstCustomer> list = cstCustomerService.queryBylike(value);
        //System.out.println("name:"+value.getCust_name());
        //List<CstCustomer> list = cstCustomerService.find(value);
        PageInfo pageInfo = new PageInfo<CstCustomer>(list, 4);

        return ResponseData.ok()
                // .putDataValue("list", list)
                .putDataValue("pageInfo", pageInfo);

    }

//    @ApiOperation("查询全部得到List<Food> json对象")
//    @RequestMapping("/CstCustomer/querydiqu")   //springboot 可以直接转json
//    public List<BasDict> querydiqu() {
//        List<BasDict> diqu = basDictService.querydiqu();
//        System.out.println("大小："+diqu.size());
//        return diqu; //自动转json  springboot
//}
//
//    @RequestMapping("/CstCustomer/querydengji")   //springboot 可以直接转json
//    public List<BasDict> querydengji() {
//    List<BasDict> list = basDictService.querydengji();
//        System.out.println("dede:"+list.toString().length());
//        return list; //自动转json  springboot
//    }

    @RequestMapping(value = "/CstCustomer/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage2(String value) {
        System.out.println("大小：");
        List<CstCustomer> list = cstCustomerService.find2(value);
//        Object[] objects = list.toArray();
//        for(Object o:objects){
//            JsonObject object=new JsonObject();
//        }
        return ResponseData.ok().putDataValue("list", list);


    }

    @RequestMapping("/CstCustomer/querydiqu")   //springboot 可以直接转json
    public List<BasDict> querydiqu(BasDict value) {
        List<BasDict> diqu = basDictService.querydiqu(value);
        //  System.out.println("大小："+diqu.size());
        return diqu; //自动转json  springboot
    }

    @RequestMapping("/CstCustomer/querydengji")   //springboot 可以直接转json
    public List<BasDict> querydengji(BasDict value) {
    List<BasDict> list = basDictService.querydengji(value);
      // System.out.println("dede:"+list.toString().length());
        return list; //自动转json  springboot
    }

    @RequestMapping("/CstCustomer/update")
    public String update(CstCustomer value) {
    cstCustomerService.updateNotNullById(value);
    return "修改成功";
    }

    //服务创建页面的客户名称赋值
    @RequestMapping(value ="/CstService/queryname/{id}", produces = {"application/json;charset=UTF-8"})
    public  ResponseData queryname(@PathVariable String id){
	    return ResponseData.ok().putDataValue("obj",cstCustomerService.queryCstname(id));
	}



    @RequestMapping("/CstService/querycst")//查询服务创建页面下拉框中的值
    public List<CstCustomer> querycst(CstCustomer value){
        List<CstCustomer> list = cstCustomerService.query(value);
        return list;
    }


//将客户信息状态改为删除
    @RequestMapping("/CstCustomer/updateStatus/{id}")
    public  String updateStatus(@PathVariable String id){
       cstCustomerService.updatestatu(id);
       return "删除成功";
    }
}
